﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JibberJabber.LivePreviews;

namespace JibberJabber.PartDesigners
{
    public partial class SpeakerDesigner : PartDesigner
    {
        public SpeakerDesigner()
        {
            InitializeComponent();
        }

        public override string StartXml
        {
            get
            {
                return "<speaker name=\"" + txtName.Text + "\" "
                    + "face=\"" + txtFace.Text + "\" x=\""
                    + ((int)updX.Value).ToString()
                    + "\" y=\"" + ((int)updY.Value).ToString() + "\" />";
            }
        }

        public override string EndXml
        {
            get
            {
                return "";
            }
        }

        public override Type[] AllowedChildren
        {
            get
            {
                return new Type[] { };
            }
        }

        private void txtName_TextChanged(object sender, EventArgs e)
        {
            if (this.AssociatedNode != null)
            {
                Program.NotifyNodeToStringOutputUpdated(this);
                Program.NotifyNodeToStringOutputUpdated(((PartDesigner)this.AssociatedNode.Parent.Tag)); // ~6/10 HACK
                ((PartDesigner)this.AssociatedNode.Parent.Tag).NotifyChildrenUpdated(); // 8/10 HACK
                LivePreview.Preview(this);
            }
        }

        public override string ToString()
        {
            return txtName.Text;
        }

        private void SpeakerDesigner_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible && this.AssociatedNode != null)
                LivePreview.Preview(this);
        }

        private void txtFace_TextChanged(object sender, EventArgs e)
        {
            if (this.AssociatedNode != null)
                LivePreview.Preview(this);
        }

        private void updX_ValueChanged(object sender, EventArgs e)
        {
            if (this.AssociatedNode != null)
                LivePreview.Preview(this);
        }

        private void updY_ValueChanged(object sender, EventArgs e)
        {
            if (this.AssociatedNode != null)
                LivePreview.Preview(this);
        }
    }
}
